using System;
using System.Collections.Generic;
using System.Text;
using SSOConfig;
using System.IO;
using SSOConfigTool.CodeGen;

namespace SSOConfigTool
{
    /// <summary>
    /// Class for generating a typed config model
    /// </summary>
    public sealed class ConfigTool
    {
        /// <summary>
        /// Generates a typed config class from an SSO application
        /// </summary>
        /// <param name="application">Populated application</param>
        /// <param name="targetNamespace">Target namespace for config model</param>
        /// <param name="outputPath">Path for generated C# file</param>
        public static void GenerateClass(SSOApplication application, string targetNamespace, string outputPath)
        {
            string code = new ConfigClassBuilder(application, targetNamespace).GetConfigClassCode();
            using (StreamWriter writer = File.CreateText(outputPath))
            {
                writer.Write(code);
                writer.Flush();
            }
        }

        /// <summary>
        /// Generates a typed config assembly from an SSO application
        /// </summary>
        /// <param name="application">Populated application</param>
        /// <param name="targetNamespace">Target namespace for config model</param>
        /// <param name="assemblyName">Path for generated assembly</param>
        public static void GenerateAssembly(SSOApplication application, string targetNamespace, string assemblyName)
        {
            ConfigAssemblyBuilder builder = new ConfigAssemblyBuilder(application, targetNamespace);
            builder.GenerateAssembly(assemblyName);
        }
    }
}
